<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      canvas {
        border: 1px solid red;
      }
    </style>
  </head>
  <body>
    <canvas width="500" height="500">
      您的浏览器版本过低，不支持canvas，请升级浏览器
    </canvas>
    <script>
      // 获取dom节点
      const canvas = document.querySelector("canvas");
      // 获取画笔
      const ctx = canvas.getContext("2d"); // 2d 表示 画的2d图
      ctx.lineWidth = 3;
      
      ctx.moveTo(100, 100);
      ctx.lineTo(400, 100);
    //   ctx.moveTo(400, 100);
      ctx.lineTo(400, 400);
    //   ctx.moveTo(400, 400);
      ctx.lineTo(100, 400);
    //   ctx.moveTo(100, 400);
      ctx.lineTo(100, 100);
      ctx.strokeStyle = "green";
      ctx.closePath();
      ctx.fillStyle = "green";
      ctx.fill();
      // 渲染
      ctx.stroke();
    </script>
  </body>
</html>
